/* GUI CONVERTED from recwoup1.p (converter v1.75) Mon Nov 13 06:36:22 2000 */
/* recwoup1.p - CUMULATIVE WORK ORDER DELETE/ARCHIVE MAIN LOOP               */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                       */
/* All rights reserved worldwide.  This is an unpublished work.              */
/*F0PN*/ /*V8:ConvertMode=FullGUIReport                                      */
/* REVISION: 8.5            CREATED: 05/09/96   BY: *G1S6* Julie Milligan    */
/* REVISION: 8.5      LAST MODIFIED: 07/26/96   BY: *J10X* Markus Barone     */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane         */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan        */
/* REVISION: 8.6E     LAST MODIFIED: 09/15/98   BY: *J2YY* Mugdha Tambe      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown        */
/* REVISION: 9.1      LAST MODIFIED: 11/08/00   BY: *N0TN* Jean Miller       */

/*THIS PROGRAM WAS COPIED FROM WOWOUP1.P */


/*GUI global preprocessor directive settings */
&GLOBAL-DEFINE PP_PGM_RP TRUE
&GLOBAL-DEFINE PP_ENV_GUI TRUE


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

         {mfdeclre.i}
         {gplabel.i} /* EXTERNAL LABEL INCLUDE */

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE recwoup1_p_1 "Archive File"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwoup1_p_2 "Delete"
/* MaxLen: Comment: */

&SCOPED-DEFINE recwoup1_p_3 "Archive"
/* MaxLen: Comment: */

/*N0TN* &SCOPED-DEFINE recwoup1_p_4 "Message # 1095" */
/* MaxLen: Comment: */

/*N0TN* &SCOPED-DEFINE recwoup1_p_5 "WORK ORDER" */
/* MaxLen: Comment: */

/*N0TN* &SCOPED-DEFINE recwoup1_p_6 "WORK ORDER COMPONENT" */
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

         define new shared variable wonbr    like wo_nbr.
         define shared variable nbr          like wo_nbr.
         define shared variable nbr1         like wo_nbr.
         define shared variable lot          like wo_lot.
         define shared variable lot1         like wo_lot.
         define shared variable part         like wo_part.
         define shared variable part1        like wo_part.
         define shared variable rel          like wo_rel_date.
         define shared variable rel1         like wo_rel_date.
         define shared variable due          like wo_due_date.
         define shared variable due1         like wo_due_date.
         define shared variable so_job       like wo_so_job.
         define shared variable so_job1      like wo_so_job.
         define shared variable proj         like wo_project.
         define shared variable vend         like wo_vend.
         define shared variable rdelete      like mfc_logical label {&recwoup1_p_2}.
         define shared variable archive      like mfc_logical label {&recwoup1_p_3}
                initial yes.
         define shared variable filename     as character format "x(12)"
                label {&recwoup1_p_1}.

         define variable base_id             like wo_base_id.
         define variable msgdesc             as character format "x(40)".

         define new shared frame b.
         define new shared stream history.
         

         FORM /*GUI*/ 
            wo_nbr
            wo_lot
            wo_part
            wo_qty_comp
            wo_due_date
            wo_so_job
            wo_status
            msgdesc no-label
         with STREAM-IO /*GUI*/  frame b width 132 down.

         /* SET EXTERNAL LABELS */
         setFrameLabels(frame b:handle).

         output stream history close.
         if archive then output stream history to value(filename) append.

         for each wo_mstr exclusive-lock
         where (wo_nbr >= nbr and wo_nbr <= nbr1)
         and (wo_lot >= lot and wo_lot <= lot1)
         and wo_type = "C"
         use-index wo_type_nbr
         with frame b down:
            if (wo_part >= part and wo_part <= part1)
            and (wo_project = proj or proj = "")
            and (wo_vend = vend or vend = "")
            and (wo_due_date >= due or due = ?)
            and (wo_due_date <= due1 or due1 = ?)
            and (wo_rel_date >= rel or rel = ?)
            and (wo_rel_date <= rel1 or rel1 = ?)
            and (wo_so_job >= so_job) and (wo_so_job <= so_job or so_job = "")
            and wo_status = "C"
            and wo_wip_tot = 0
            then do:

/*J10X*        if not can-find(qad_wkfl where qad_key1 = "WO-CLOSE"  */
/*J10X*        and qad_key2 = wo_lot)                                */
/*J10X*/       if not wo_acct_close
                  then next.

               pause 0 no-message.

               if wo_joint_type <> "" then do:
                  /* SKIP IF THE JP WORK ORDER SET HAS ALREADY BEEN PROCESSED */
                  if wo_nbr = wonbr then next.
                  wonbr = wo_nbr.

                  /* PROCESS JOINT WOs AS A SET */
                  {gprun.i ""wowoup2.p""}
                  next.
               end.

               /* ISSUE WARNING IF QUALITY TEST RESULTS EXIST FOR THIS W/O */
               find first mph_hist where mph_lot = wo_lot no-lock no-error.

               /* BEGIN ADDED BLOCK */
               msgdesc = "".
               if available mph_hist then do:
                  /*Warning: Quality Results Exist*/
/*N0TN*           find msg_mstr where msg_nbr = 1095                 */
/*N0TN*           and msg_lang = global_user_lang no-lock no-error.  */
/*N0TN*           if available msg_mstr then msgdesc = msg_desc.     */
/*N0TN*           else msgdesc = {&recwoup1_p_4}.                    */
/*N0TN*/          {pxmsg.i &MSGNUM=1095 &ERRORLEVEL=1 &MSGBUFFER=msgdesc}
               end.
               /* END ADDED BLOCK */

               display wo_nbr wo_lot wo_part wo_qty_comp
               wo_due_date wo_so_job wo_status
               msgdesc
               with frame b STREAM-IO /*GUI*/ .
               down 1 with frame b.

               /* DELETE WORK ORDER AND DETAIL */
               for each wod_det exclusive-lock where wod_lot = wo_lot:

/*N0TN*/          /* Changed pre-processor to a Term */
                  {mfmrw.i "wod_det" wod_part wod_nbr wod_lot """" ?
                  wod_iss_date "0" "DEMAND" WORK_ORDER_COMPONENT wod_site}

/*N0TN*/          /* Changed pre-processor to a Term */
                  {mfmrw.i "wod_det" wod_part wod_nbr wod_lot string(wod_op) ?
                  wod_iss_date "0" "DEMAND" WORK_ORDER_COMPONENT wod_site}

                  if archive then do:
                     export stream history "wod_det".
                     export stream history wod_det.
                  end.

                  /*DELETE COMMENTS */
                  for each cmt_det exclusive-lock where cmt_indx = wod_cmtindx:
                     if archive then do:
                        export stream history "cmt_det".
                        export stream history cmt_det.
                     end.
                     if rdelete then delete cmt_det.
                  end.

                  /*DELETE QAD_WKFL*/
                  find qad_wkfl exclusive-lock where qad_key1 = "MFWORLA"
                  and qad_key2 = wod_lot + wod_part + string(wod_op) no-error.
                  if available qad_wkfl then do:
                     if archive then do:
                        export stream history "qad_wkfl".
                        export stream history qad_wkfl.
                     end.
                     if rdelete then delete qad_wkfl.
                  end.
                  if rdelete then delete wod_det.
               end. /* wod_det */

               /* ARCHIVE/DELETE WORK ORDER ROUTING */
               for each wr_route exclusive-lock where wr_lot = wo_lot:
                  if archive then do:
                     export stream history "wr_route".
                     export stream history wr_route.
                  end.
                  /* DELETE COMMENTS */
                  for each cmt_det exclusive-lock
                  where cmt_indx = wr_cmtindx:
                     if archive then do:
                        export stream history "cmt_det".
                        export stream history cmt_det.
                     end.
                     if rdelete then delete cmt_det.
                  end.
                  if rdelete then delete wr_route.
               end. /* each wr_route */

/*J2YY*/      /* ARCHIVE/DELETE ITEM COST ROUTING DETAILS */

/*J2YY*/      /* BEGIN ADD SECTION                   */

               for each iro_det exclusive-lock
                  where iro_part = wo_part
                    and iro_site = wo_site
                    and iro_cost_set begins "cumorder"
                    and iro_routing = wo_lot:

                  if archive then do:
                     export stream history "iro_det".
                     export stream history iro_det.
                  end.

                  if rdelete then delete iro_det .

               end. /* FOR EACH IRO_DET */

/*J2YY*/      /* END   ADD SECTION                   */

               /* ARCHIVE/DELETE WORK ORDER */
/*N0TN*/       /* Changed pre-processor to a term */
               {mfmrw.i "wo_mstr" wo_part wo_nbr wo_lot """"
                wo_rel_date wo_due_date "0" "SUPPLY" WORK_ORDER wo_site}

               {mfmrw.i "wo_scrap" wo_part wo_nbr wo_lot """"
                wo_rel_date wo_due_date "0" "DEMAND" """" wo_site}

               if archive then do:
                  export stream history "wo_mstr".
                  export stream history wo_mstr.
               end.

               for each cmt_det exclusive-lock where cmt_indx = wo_cmtindx:
                  if archive then do:
                     export stream history "cmt_det".
                     export stream history cmt_det.
                  end.
                  if rdelete then delete cmt_det.
               end.
/*J10X**BEGIN DELETE**
 *             find qad_wkfl exclusive-lock where qad_key1 = "WO-CLOSE"
 *             and qad_key2 = wo_lot no-error.
 *             if available qad_wkfl then do:
 *                if archive then do:
 *                   export stream history "qad_wkfl".
 *                   export stream history qad_wkfl.
 *                end.
 *                if rdelete then delete qad_wkfl.
 *             end.
 *J10X**END DELETE**/
               if rdelete then delete wo_mstr.
            end. /* (wo_part >= part .... */
         end.  /* for each wo_mstr */

         output stream history close.
